using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Forms;
using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;
using NPOI.XSSF.UserModel;
using fuzhu;
using LKU8.shoukuan;
using System.ComponentModel;
using System.Text.RegularExpressions;

namespace fuzhu
{
    /// <summary>
    /// 万吉发货Excel导入助手
    /// 专门处理万吉发货Excel模板的导入
    /// </summary>
    public class WanJiExcelImportHelper_Fahuo
    {
        private static WriteLog wl = new WriteLog();

        /// <summary>
        /// 从Excel文件导入万吉发货数据
        /// </summary>
        /// <param name="filePath">Excel文件路径</param>
        /// <param name="selectedDate">选择的发货日期</param>
        /// <returns>导入的发货数据列表</returns>
        public static BindingList<WanJi_FaHuo_View> ImportFromExcel(string filePath, DateTime selectedDate)
        {
            return ImportFromExcel(filePath, 0, selectedDate); // 默认使用第一个工作表
        }

        /// <summary>
        /// 从Excel文件的指定工作表导入万吉发货数据
        /// </summary>
        /// <param name="filePath">Excel文件路径</param>
        /// <param name="sheetIndex">工作表索引</param>
        /// <param name="selectedDate">选择的发货日期</param>
        /// <returns>导入的发货数据列表</returns>
        public static BindingList<WanJi_FaHuo_View> ImportFromExcel(string filePath, int sheetIndex, DateTime selectedDate)
        {
            BindingList<WanJi_FaHuo_View> resultList = new BindingList<WanJi_FaHuo_View>();
            
            try
            {
                IWorkbook workbook;
                using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    workbook = WorkbookFactory.Create(file);
                }

                if (sheetIndex >= workbook.NumberOfSheets)
                {
                    throw new Exception(string.Format("工作表索引 {0} 超出范围，文件只有 {1} 个工作表", sheetIndex, workbook.NumberOfSheets));
                }

                ISheet sheet = workbook.GetSheetAt(sheetIndex);
                
                if (sheet == null)
                {
                    throw new Exception("Excel文件中没有找到工作表");
                }

                // 获取标题行（第二行，索引为1）
                IRow headerRow = sheet.GetRow(1);
                if (headerRow == null)
                {
                    throw new Exception("Excel文件中没有找到标题行（第二行）");
                }

                // 解析标题行，建立列名到列索引的映射
                Dictionary<string, int> columnMapping = ParseHeaderRow(headerRow);

                // 验证必需的列是否存在
                ValidateRequiredColumns(columnMapping);

                // 查找日期列
                int dateColumnIndex = FindDateColumn(columnMapping, selectedDate);
                if (dateColumnIndex == -1)
                {
                    throw new Exception(string.Format("未找到日期 {0:yyyy-MM-dd} 对应的列", selectedDate));
                }

                // 从第三行开始读取数据（索引为2）
                int rowIndex = 2;

                while (rowIndex <= sheet.LastRowNum)
                {
                    IRow row = sheet.GetRow(rowIndex);
                    if (row == null)
                    {
                        rowIndex++;
                        continue;
                    }

                    // 检查工单号是否为空，如果为空则停止读取
                    string moCode = GetCellValue(row, columnMapping, "工单号");
                    if (string.IsNullOrEmpty(moCode))
                    {
                        rowIndex++;
                        continue; // 工单号为空，跳过这一行
                    }

                    // 检查该日期列是否有数据
                    ICell dateCell = row.GetCell(dateColumnIndex);
                    string fahuoQtyValue = GetCellStringValue(dateCell);
                    if (string.IsNullOrEmpty(fahuoQtyValue) || fahuoQtyValue=="0")
                    {
                        rowIndex++;
                        continue; // 该日期列没有数据，跳过这一行
                    }

                    // 创建发货视图对象
                    WanJi_FaHuo_View fahuoView = new WanJi_FaHuo_View();
                    
                    // 填充数据
                    FillFahuoData(fahuoView, row, columnMapping, selectedDate, fahuoQtyValue);
                    
                    resultList.Add(fahuoView);
                    
                    rowIndex++;
                }

                return resultList;
            }
            catch (Exception ex)
            {
                wl.WriteLogs("导入Excel时发生错误: " + ex.Message);
                throw new Exception("导入Excel文件失败：" + ex.Message, ex);
            }
        }

        /// <summary>
        /// 解析标题行，建立列名到列索引的映射
        /// </summary>
        /// <param name="headerRow">标题行</param>
        /// <returns>列名到列索引的映射字典</returns>
        private static Dictionary<string, int> ParseHeaderRow(IRow headerRow)
        {
            Dictionary<string, int> columnMapping = new Dictionary<string, int>();
            
            for (int i = 0; i <= headerRow.LastCellNum; i++)
            {
                ICell cell = headerRow.GetCell(i);
                if (cell != null)
                {
                    string cellValue = GetHeaderCellValue(cell).Trim();
                    if (!string.IsNullOrEmpty(cellValue))
                    {
                        columnMapping[cellValue] = i;
                    }
                }
            }

            return columnMapping;
        }

        /// <summary>
        /// 验证必需的列是否存在
        /// </summary>
        /// <param name="columnMapping">列名映射</param>
        private static void ValidateRequiredColumns(Dictionary<string, int> columnMapping)
        {
            string[] requiredColumns = { "工单号", "批量", "订单号", "工单剩余", "累计" };
            List<string> missingColumns = new List<string>();

            foreach (string required in requiredColumns)
            {
                if (!columnMapping.ContainsKey(required))
                {
                    missingColumns.Add(required);
                }
            }

            if (missingColumns.Count > 0)
            {
                throw new Exception("Excel模板缺少必需的列：" + string.Join(", ", missingColumns.ToArray()));
            }
        }

        /// <summary>
        /// 获取标题行单元格的值（特殊处理日期数字）
        /// </summary>
        /// <param name="cell">单元格</param>
        /// <returns>字符串值</returns>
        private static string GetHeaderCellValue(ICell cell)
        {
            if (cell == null)
            {
                return "";
            }

            try
            {
                switch (cell.CellType)
                {
                    case CellType.STRING:
                        //return cell.StringCellValue.Trim();
                        return Regex.Replace(cell.StringCellValue, @"\s", "");
                    case CellType.NUMERIC:
                        // 检查是否为日期格式
                        if (DateUtil.IsCellDateFormatted(cell))
                        {
                            DateTime date = cell.DateCellValue;
                            // 返回多种日期格式，优先返回标准格式
                            return date.ToString("yyyy-MM-dd"); // 如：2024-09-13
                        }
                        else
                        {
                            // 尝试将数字转换为Excel日期
                            double numValue = cell.NumericCellValue;
                            if (numValue > 1 && numValue < 2958466) // Excel日期范围（1900-01-01 到 9999-12-31）
                            {
                                try
                                {
                                    DateTime excelDate = DateTime.FromOADate(numValue);
                                    // 返回多种日期格式
                                    return excelDate.ToString("yyyy-MM-dd"); // 如：2024-09-13
                                }
                                catch
                                {
                                    // 如果不是有效的Excel日期，返回原数字
                                    return numValue.ToString();
                                }
                            }
                            else
                            {
                                return numValue.ToString();
                            }
                        }
                    case CellType.BOOLEAN:
                        return cell.BooleanCellValue.ToString();
                    case CellType.FORMULA:
                        return GetHeaderFormulaValue(cell);
                    case CellType.BLANK:
                        return "";
                    case CellType.ERROR:
                        wl.WriteLogs(string.Format("标题单元格错误: {0}", cell.ErrorCellValue));
                        return "";
                    default:
                        return "";
                }
            }
            catch (Exception ex)
            {
                wl.WriteLogs(string.Format("获取标题单元格值错误: {0}", ex.Message));
                return "";
            }
        }

        /// <summary>
        /// 获取标题行公式单元格的值
        /// </summary>
        /// <param name="cell">公式单元格</param>
        /// <returns>公式计算结果</returns>
        private static string GetHeaderFormulaValue(ICell cell)
        {
            try
            {
                IFormulaEvaluator evaluator = cell.Sheet.Workbook.GetCreationHelper().CreateFormulaEvaluator();
                CellValue cellValue = evaluator.Evaluate(cell);
                
                switch (cellValue.CellType)
                {
                    case CellType.STRING:
                        return cellValue.StringValue.Trim();
                    case CellType.NUMERIC:
                        // 检查是否为日期格式
                        if (DateUtil.IsCellDateFormatted(cell))
                        {
                            DateTime date = DateUtil.GetJavaDate(cellValue.NumberValue);
                            return date.ToString("yyyy-MM-dd"); // 如：2024-09-13
                        }
                        else
                        {
                            // 尝试将数字转换为Excel日期
                            double numValue = cellValue.NumberValue;
                            if (numValue > 1 && numValue < 2958466)
                            {
                                try
                                {
                                    DateTime excelDate = DateTime.FromOADate(numValue);
                                    return excelDate.ToString("yyyy-MM-dd");
                                }
                                catch
                                {
                                    return numValue.ToString();
                                }
                            }
                            else
                            {
                                return numValue.ToString();
                            }
                        }
                    case CellType.BOOLEAN:
                        return cellValue.BooleanValue.ToString();
                    case CellType.ERROR:
                        wl.WriteLogs(string.Format("标题公式计算错误: {0}", cellValue.ErrorValue));
                        return "";
                    default:
                        return "";
                }
            }
            catch (Exception ex)
            {
                wl.WriteLogs(string.Format("标题公式计算异常: {0}", ex.Message));
                
                try
                {
                    switch (cell.CachedFormulaResultType)
                    {
                        case CellType.STRING:
                            return cell.StringCellValue.Trim();
                        case CellType.NUMERIC:
                            if (DateUtil.IsCellDateFormatted(cell))
                            {
                                return cell.DateCellValue.ToString("yyyy-MM-dd");
                            }
                            else
                            {
                                double numValue = cell.NumericCellValue;
                                if (numValue > 1 && numValue < 2958466)
                                {
                                    try
                                    {
                                        DateTime excelDate = DateTime.FromOADate(numValue);
                                        return excelDate.ToString("yyyy-MM-dd");
                                    }
                                    catch
                                    {
                                        return numValue.ToString();
                                    }
                                }
                                else
                                {
                                    return numValue.ToString();
                                }
                            }
                        case CellType.BOOLEAN:
                            return cell.BooleanCellValue.ToString();
                        default:
                            return "";
                    }
                }
                catch
                {
                    wl.WriteLogs("无法获取标题公式结果，返回空值");
                    return "";
                }
            }
        }
        private static int FindDateColumn(Dictionary<string, int> columnMapping, DateTime selectedDate)
        {
            // 尝试多种日期格式
            string[] dateFormats = {
                selectedDate.ToString("yyyy-MM-dd"), // 2024-09-13
                selectedDate.ToString("M/d"),    // 9/13
                selectedDate.ToString("M月d日"),  // 9月13日
                selectedDate.ToString("MM/dd"),   // 09/13
                selectedDate.ToString("M/dd"),    // 9/13
                selectedDate.ToString("MM/d"),    // 09/3
                selectedDate.ToString("yyyy-M-d"), // 2024-9-13
                selectedDate.ToString("yyyy/M/d"), // 2024/9/13
                selectedDate.ToString("M-d"),      // 9-13
                selectedDate.ToString("d")         // 13（只有日期数字）
            };

            foreach (string format in dateFormats)
            {
                if (columnMapping.ContainsKey(format))
                {
                    return columnMapping[format];
                }
            }

            // 如果上面的格式都找不到，尝试匹配日期模式
            foreach (var kvp in columnMapping)
            {
                if (IsDateColumnMatch(kvp.Key, selectedDate))
                {
                    return kvp.Value;
                }
            }

            return -1;
        }

        /// <summary>
        /// 检查列名是否与日期匹配
        /// </summary>
        /// <param name="columnName">列名</param>
        /// <param name="selectedDate">选择的日期</param>
        /// <returns>是否匹配</returns>
        private static bool IsDateColumnMatch(string columnName, DateTime selectedDate)
        {
            if (string.IsNullOrEmpty(columnName))
                return false;

            // 尝试解析列名为日期
            DateTime parsedDate;
            string[] parseFormats = {
                "yyyy-MM-dd", "yyyy-M-d", "yyyy/MM/dd", "yyyy/M/d",
                "M/d", "MM/dd", "M/dd", "MM/d",
                "M月d日", "MM月dd日",
                "M-d", "MM-dd",
                "d"
            };

            foreach (string format in parseFormats)
            {
                if (DateTime.TryParseExact(columnName, format, null, System.Globalization.DateTimeStyles.None, out parsedDate))
                {
                    // 比较月和日
                    if (parsedDate.Month == selectedDate.Month && parsedDate.Day == selectedDate.Day)
                    {
                        return true;
                    }
                }
            }

            // 尝试通用日期解析
            if (DateTime.TryParse(columnName, out parsedDate))
            {
                if (parsedDate.Month == selectedDate.Month && parsedDate.Day == selectedDate.Day)
                {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// 从行中获取指定列的值
        /// </summary>
        /// <param name="row">数据行</param>
        /// <param name="columnMapping">列名映射</param>
        /// <param name="columnName">列名</param>
        /// <returns>单元格值</returns>
        private static string GetCellValue(IRow row, Dictionary<string, int> columnMapping, string columnName)
        {
            if (!columnMapping.ContainsKey(columnName))
            {
                return "";
            }

            int columnIndex = columnMapping[columnName];
            ICell cell = row.GetCell(columnIndex);
            
            return GetCellStringValue(cell);
        }

        /// <summary>
        /// 获取单元格的字符串值
        /// </summary>
        /// <param name="cell">单元格</param>
        /// <returns>字符串值</returns>
        private static string GetCellStringValue(ICell cell)
        {
            if (cell == null)
            {
                return "";
            }

            try
            {
                switch (cell.CellType)
                {
                    case CellType.STRING:
                        return cell.StringCellValue.Trim();
                    case CellType.NUMERIC:
                        if (DateUtil.IsCellDateFormatted(cell))
                        {
                            return cell.DateCellValue.ToString("yyyy-MM-dd");
                        }
                        else
                        {
                            return cell.NumericCellValue.ToString();
                        }
                    case CellType.BOOLEAN:
                        return cell.BooleanCellValue.ToString();
                    case CellType.FORMULA:
                        return GetFormulaValue(cell);
                    case CellType.BLANK:
                        return "";
                    case CellType.ERROR:
                        wl.WriteLogs(string.Format("单元格错误: {0}", cell.ErrorCellValue));
                        return "";
                    default:
                        return "";
                }
            }
            catch (Exception ex)
            {
                wl.WriteLogs(string.Format("获取单元格值错误: {0}", ex.Message));
                return "";
            }
        }

        /// <summary>
        /// 获取公式单元格的值
        /// </summary>
        /// <param name="cell">公式单元格</param>
        /// <returns>公式计算结果</returns>
        private static string GetFormulaValue(ICell cell)
        {
            try
            {
                IFormulaEvaluator evaluator = cell.Sheet.Workbook.GetCreationHelper().CreateFormulaEvaluator();
                CellValue cellValue = evaluator.Evaluate(cell);
                
                switch (cellValue.CellType)
                {
                    case CellType.STRING:
                        return cellValue.StringValue.Trim();
                    case CellType.NUMERIC:
                        if (DateUtil.IsCellDateFormatted(cell))
                        {
                            return DateUtil.GetJavaDate(cellValue.NumberValue).ToString("yyyy-MM-dd");
                        }
                        else
                        {
                            return cellValue.NumberValue.ToString();
                        }
                    case CellType.BOOLEAN:
                        return cellValue.BooleanValue.ToString();
                    case CellType.ERROR:
                        wl.WriteLogs(string.Format("公式计算错误: {0}", cellValue.ErrorValue));
                        return "";
                    default:
                        return "";
                }
            }
            catch (Exception ex)
            {
                wl.WriteLogs(string.Format("公式计算异常: {0}", ex.Message));
                
                try
                {
                    switch (cell.CachedFormulaResultType)
                    {
                        case CellType.STRING:
                            return cell.StringCellValue.Trim();
                        case CellType.NUMERIC:
                            if (DateUtil.IsCellDateFormatted(cell))
                            {
                                return cell.DateCellValue.ToString("yyyy-MM-dd");
                            }
                            else
                            {
                                return cell.NumericCellValue.ToString();
                            }
                        case CellType.BOOLEAN:
                            return cell.BooleanCellValue.ToString();
                        default:
                            return "";
                    }
                }
                catch
                {
                    wl.WriteLogs("无法获取公式结果，返回空值");
                    return "";
                }
            }
        }

        /// <summary>
        /// 填充发货数据
        /// </summary>
        /// <param name="fahuoView">发货视图对象</param>
        /// <param name="row">数据行</param>
        /// <param name="columnMapping">列名映射</param>
        /// <param name="selectedDate">选择的日期</param>
        /// <param name="fahuoQtyValue">发货数量值</param>
        private static void FillFahuoData(WanJi_FaHuo_View fahuoView, IRow row, Dictionary<string, int> columnMapping, DateTime selectedDate, string fahuoQtyValue)
        {
            try
            {
                // 基础字段映射
                fahuoView.cMoCode = GetCellValue(row, columnMapping, "工单号");
                fahuoView.cSoCode = GetCellValue(row, columnMapping, "销售订单号");
                fahuoView.cInvCode = GetCellValue(row, columnMapping, "U8编码");
                fahuoView.cJiZhongName = GetCellValue(row, columnMapping, "机种名");
                fahuoView.cXiLie = GetCellValue(row, columnMapping, "系列");
                fahuoView.cHangNo = GetCellValue(row, columnMapping, "行号");
                // 处理订单批量
                string batchValue = GetCellValue(row, columnMapping, "批量");
                if (!string.IsNullOrEmpty(batchValue))
                {
                    int parsedBatch;
                    if (int.TryParse(batchValue, out parsedBatch))
                    {
                        fahuoView.iMoQty = parsedBatch;
                    }
                }

                // 处理工单剩余
                string remainValue = GetCellValue(row, columnMapping, "工单剩余");
                if (!string.IsNullOrEmpty(remainValue))
                {
                    int parsedRemain;
                    if (int.TryParse(remainValue, out parsedRemain))
                    {
                        fahuoView.iWFHQty = parsedRemain;
                    }
                }

                // 处理累计
                string totalValue = GetCellValue(row, columnMapping, "累计");
                if (!string.IsNullOrEmpty(totalValue))
                {
                    int parsedTotal;
                    if (int.TryParse(totalValue, out parsedTotal))
                    {
                        fahuoView.iYFHQty = parsedTotal;
                    }
                }

                // 设置发货日期
                fahuoView.dDate = selectedDate;

                // 处理发货数量
                if (!string.IsNullOrEmpty(fahuoQtyValue))
                {
                    // 去掉可能的非数字字符
                    string numericValue = Regex.Replace(fahuoQtyValue, @"[^\d.]", "");
                    int parsedQty;
                    double parsedDouble;

                    if (int.TryParse(numericValue, out parsedQty))
                    {
                        fahuoView.iFHQty = parsedQty;
                    }
                    else if (double.TryParse(numericValue, out parsedDouble))
                    {
                        fahuoView.iFHQty = (int)parsedDouble;
                    }
                    else
                    {
                        fahuoView.iFHQty = 0;
                    }
                }

                // 初始化默认值
                fahuoView.chk = false;
                fahuoView.bU8 = false;
                fahuoView.cImportResult = "";
            }
            catch (Exception ex)
            {
                wl.WriteLogs("填充发货数据时发生错误: " + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 获取Excel文件中所有工作表的名称
        /// </summary>
        /// <param name="filePath">Excel文件路径</param>
        /// <returns>工作表名称列表</returns>
        public static List<string> GetSheetNames(string filePath)
        {
            List<string> sheetNames = new List<string>();
            
            try
            {
                IWorkbook workbook;
                using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    workbook = WorkbookFactory.Create(file);
                }

                for (int i = 0; i < workbook.NumberOfSheets; i++)
                {
                    sheetNames.Add(workbook.GetSheetName(i));
                }
            }
            catch (Exception ex)
            {
                wl.WriteLogs("获取工作表名称时发生错误: " + ex.Message);
                throw;
            }

            return sheetNames;
        }

        /// <summary>
        /// 验证Excel文件格式是否正确
        /// </summary>
        /// <param name="filePath">Excel文件路径</param>
        /// <returns>验证结果信息</returns>
        public static string ValidateExcelFormat(string filePath)
        {
            try
            {
                IWorkbook workbook;
                using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    workbook = WorkbookFactory.Create(file);
                }

                ISheet sheet = workbook.GetSheetAt(0);
                if (sheet == null)
                {
                    return "Excel文件中没有工作表";
                }

                // 检查是否有足够的行数
                if (sheet.LastRowNum < 2)
                {
                    return "Excel文件数据不足，至少需要3行（第二行标题+数据行）";
                }

                // 检查第二行是否有标题
                IRow headerRow = sheet.GetRow(1);
                if (headerRow == null)
                {
                    return "第二行（标题行）不存在";
                }

                // 解析标题行
                Dictionary<string, int> columnMapping = ParseHeaderRow(headerRow);
                
                // 验证必需列
                try
                {
                    ValidateRequiredColumns(columnMapping);
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }

                return "Excel格式验证通过";
            }
            catch (Exception ex)
            {
                wl.WriteLogs("验证Excel格式时发生错误: " + ex.Message);
                return "验证Excel格式失败：" + ex.Message;
            }
        }

        /// <summary>
        /// 获取Excel中所有的列名（用于调试）
        /// </summary>
        /// <param name="filePath">Excel文件路径</param>
        /// <returns>列名列表</returns>
        public static List<string> GetAllColumnNames(string filePath)
        {
            List<string> columnNames = new List<string>();
            
            try
            {
                IWorkbook workbook;
                using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    workbook = WorkbookFactory.Create(file);
                }

                ISheet sheet = workbook.GetSheetAt(0);
                if (sheet == null)
                {
                    return columnNames;
                }

                IRow headerRow = sheet.GetRow(1);
                if (headerRow == null)
                {
                    return columnNames;
                }

                for (int i = 0; i <= headerRow.LastCellNum; i++)
                {
                    ICell cell = headerRow.GetCell(i);
                    if (cell != null)
                    {
                        string cellValue = GetHeaderCellValue(cell).Trim();
                        if (!string.IsNullOrEmpty(cellValue))
                        {
                            columnNames.Add(cellValue);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                wl.WriteLogs("获取列名时发生错误: " + ex.Message);
            }

            return columnNames;
        }
        public static List<string> GetAvailableDateColumns(string filePath)
        {
            List<string> dateColumns = new List<string>();
            
            try
            {
                IWorkbook workbook;
                using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    workbook = WorkbookFactory.Create(file);
                }

                ISheet sheet = workbook.GetSheetAt(0);
                if (sheet == null)
                {
                    return dateColumns;
                }

                IRow headerRow = sheet.GetRow(1);
                if (headerRow == null)
                {
                    return dateColumns;
                }

                Dictionary<string, int> columnMapping = ParseHeaderRow(headerRow);
                
                // 查找日期模式的列
                foreach (string columnName in columnMapping.Keys)
                {
                    // 检查是否为日期格式
                    if (IsDateColumn(columnName))
                    {
                        dateColumns.Add(columnName);
                    }
                }
            }
            catch (Exception ex)
            {
                wl.WriteLogs("获取日期列时发生错误: " + ex.Message);
            }

            return dateColumns;
        }

        /// <summary>
        /// 判断列名是否为日期格式
        /// </summary>
        /// <param name="columnName">列名</param>
        /// <returns>是否为日期格式</returns>
        private static bool IsDateColumn(string columnName)
        {
            // 匹配日期格式的正则表达式
            string[] datePatterns = {
                @"^\d{4}-\d{1,2}-\d{1,2}$", // 2024-9-13, 2024-09-13
                @"^\d{1,2}/\d{1,2}$",     // 9/13, 09/13
                @"^\d{1,2}月\d{1,2}日$",   // 9月13日
                @"^\d{4}/\d{1,2}/\d{1,2}$", // 2024/9/13
                @"^\d{1,2}-\d{1,2}$",      // 9-13
                @"^\d{1,2}$"               // 13（只有日期数字）
            };

            foreach (string pattern in datePatterns)
            {
                if (Regex.IsMatch(columnName, pattern))
                {
                    return true;
                }
            }

            return false;
        }
    }
}